<template>
	<m-layout class="layout-box flex-column" barBg="unset" :goBack="goBack">
		<view class="login flex-column">
			<view class="image-box flex-column flex-between mt-200">
				<!-- <m-image :size="[180,180]" src="../../static/images/logo4.png" /> -->
			</view>
			<view class="box plr-24">
				<view class="from flex-column">
					<view class="flex-column pb-48">
						<text class="fs48 fw-600" style="color: #555">您好！</text>
						<text class="fs36 fw-600" style="color: #555">歡迎來到GRBQ農場</text>
					</view>
					<text class="fs30 mb-12">密碼</text>
					<m-block gap="0 24 0 12" spa="0 0 20" radius="20">
						<m-fromItem icon="mima" border="0" type="password" placeholder="請輸入密碼" v-model="loginPassword" />
					</m-block>
					<view class="hint flex">
						<m-icon
							:type="isChecked ? 'icon-xuanzhong' : 'icon-fuxuanxiangweixuanzhong'"
							size="34"
							spa="0 10 0 0"
							@click="isChecked = !isChecked"
							:color="isChecked ? 'var(--theme)' : ''"
						></m-icon>
						<text @click="isChecked = !isChecked" class="">我已閱讀並同意</text>
						<text class="yhxy" @click="goWeb('/static/html/agreement.html')">《用戶协议》</text>
						<text>和</text>
						<text class="yhxy" @click="goWeb('/static/html/privacy.html')">《隱私协议》</text>
					</view>
					<view class="flex-between" style="margin-top: 60rpx; margin-bottom: 66rpx">
						<text class="login_text2" @click="Jump('/pages/login/retrieved/retrieved')">忘記密碼?</text>
						<text class="login_text" @click="Jump('/pages/login/register/register')">註冊</text>
					</view>
					<view style="margin-top: 60rpx">
						<m-button @click="login" :loading="loading">立即登錄</m-button>
					</view>
					<!-- <view class="flex jc-center mt-20" @click="getOAID">
						<text class="fs24">获取OAID</text>
					</view> -->
					<!-- <downLink v-if="platForm == 'web'" class="downLinKBox mt-100" :type="2" /> -->
					<!-- <icp /> -->
				</view>
			</view>
		</view>
	</m-layout>
</template>

<script>
import { Encrypt, Decrypt } from '@/libs/fn/aes.js';
import cookie from '@/utils/auth.js';
import Updater from '@/utils/upgrade.js';
import { email, mobile } from '@/libs/fn/verify.js'; // 引入验证工具库
import downLink from './components/link.vue';
import { Login_Phone, IMEI_PhoneRegister, IMEI_RegisterVerify } from '@/api/Users.js';
import { device_getOAID } from '@/utils/plusTool.js';
export default {
	components: { downLink },
	data() {
		return {
			// loginAccount: '864297060331813',
			// loginAccount: '860594043770305',
			loginAccount: '',
			isChecked: false,
			loading: false,
			loginPassword: '',
			system: {},
			goBack: false
		};
	},
	computed: {
		platForm() {
			return this.Cookie.get('PlatForm');
		}
	},
	async onLoad({ goBack }) {
		this.goBack = goBack == 'true' ? true : false || false;
		console.log('goBack===>', goBack);
		this.loginAccount = this.Cookie.get('uniqueID');
		this.init();
	},
	methods: {
		async getOAID() {
			try {
				// #ifdef APP-PLUS
				const oaid = await device_getOAID();
				this.Toast(oaid ? oaid : '获取失败');
				// #endif
				//#ifdef H5
				this.Toast('H5暂不支持');
				// #endif
			} catch (error) {
				this.Toast('获取失败',error);
			}
		},
		goWeb(url) {
			uni.navigateTo({
				url: '/pages/webview/webview?url=' + url
			});
		},
		async init() {
			try {
				// 版本檢查
				const { isUpdate } = await Updater.check();
				console.log('isUpdate===>', isUpdate);
				// if (this.loginAccount) {
				// 	console.log('loginAccount===>', this.loginAccount);
				// 	const { success } = await IMEI_RegisterVerify({
				// 		imei: this.loginAccount
				// 	});
				// 	console.log('success===是否注册', success);
				// 	// if(!success) this.Jump('/pages/login/register/register');
				// }
			} catch (e) {
				console.log(e);
			}
		},
		async login() {
			if (!this.isChecked) return this.Toast('请勾选用户协议');
			if (!this.loginPassword) return this.Toast('请输入密码');
			if (!cookie.get('FarmActivationCode')) return this.Toast('暂无账号');
			this.loading = true;
			const { success } = await IMEI_PhoneRegister({
				deviceToken: cookie.get('DeciceToken'),
				password: this.loginPassword,
				farmActivationCode: cookie.get('FarmActivationCode')
			});
			this.loading = false;
			console.log(this.loading);
		}
	}
};
</script>
<style lang="scss">
page {
	background-color: #ffffff;
	background-image: url('@/static/images/pages/login/registerBg.png');
	background-repeat: no-repeat;
	background-size: 100% 100%;
}
.layout-box {
	// background-color: #fff;
	height: 100%;
	box-sizing: border-box;
	background-image: url('@/static/images/pages/login/loginbg_img.png');
	background-repeat: no-repeat;
	background-position: center top;
	background-size: 490rpx 457rpx;
	// background-color: #59DA72;
	// background: linear-gradient(90deg, #00CC92 0%, #38cc1e 100%);

	::v-deep .layout-content {
		flex: 1;
		padding-bottom: 0 !important;
	}
}

// 背景
.login {
	height: 100%;

	.image-box {
		text-align: center;
		padding: 100rpx 0 8vh 0;

		image:nth-of-type(1) {
			display: inline-block;
			width: 174rpx;
			height: 174rpx;
		}

		image:nth-of-type(2) {
			padding-top: 25rpx;
			display: inline-block;
			width: 264rpx;
			height: 84rpx;
		}
	}

	.box {
		flex: 1;
		padding-top: 40rpx;
		// background-color: #FFF;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;

		.from {
			padding: 0 30rpx;
			overflow: hidden;
			.input_box {
				padding: 70rpx 0 24rpx 0;
				border-bottom: 3rpx solid #bfbfbf;
			}
			.block {
				background: #ffffff;
			}
			.login_text {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				// text-decoration: underline;
				color: #004d30;
			}

			.login_text2 {
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(102, 102, 102, 0.8);
			}
		}
	}
}

.hint {
	padding-bottom: 40rpx;
	padding-top: 50rpx;

	text {
		font-size: var(--fs_28);
		color: var(--text_1);
	}

	.yhxy {
		color: var(--theme);
	}
}
</style>
